#include "allowance_type.hpp"
#include "file_list.hpp"

allowance_type_struct_csv const allowance_type_csv::find(int _id)
{
	csv_struct csv_file(file_list::allowance_type_filename());
	while(_id && !csv_file.eof())
	{
		++csv_file;
		allowance_type_struct_csv row(csv_file.get_line());
			
		if(row.id() != _id) continue;
			
		return row;

	}

	allowance_type_struct_csv allowance_type_struct_csv_null;
	return allowance_type_struct_csv_null;
}

int allowance_type_csv::num()
{
	if(max_num()) return max_num();

	csv_struct csv_file(file_list::allowance_type_filename());
	int id(0);

	while(!csv_file.eof())
	{
		++csv_file;
		allowance_type_struct_csv row(csv_file.get_line());
			
		if(row.id() <= id) continue;
			
		id = row.id();
	}

	max_num(id);
	return id;
}

int allowance_type_csv::max_num(int _num)
{
	static int max_num;

	if(_num)
	{
		max_num = _num;
	}

	return max_num;
}
